#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
#include "list.h"

int init(list_t *stack) {
    initList(stack);
}
 

int push(list_t *stack, list_t *node) {
    list_add((list_t *)node, (list_t *)stack);
}

// other pop method, returen node address and errorCode
// == STACK_OK if stack is not empty, 
// otherwise return STACK_EMPTY
list_t *pop(list_t *stack, int *errorCode) {
    *errorCode =  isEmpty(stack) ? STACK_FAIL: STACK_OK;
    if (*errorCode == STACK_OK) {
        list_t *entry = stack->next;
        list_del(entry);
        return entry;
    }
    return NULL;
};

int isEmpty(list_t *stack) {
    return list_isEmpty(stack);
}

// return 1 if node is contained in stack, 
// where compareFunc is your compare funtion.
// compareFunc return 0 if key of elementNode == key (integer, float or string)  
// return 1 if x is contained in stack
int isExist(list_t *stack, void *key, int (*compareFunc)(void *elementNode, void *key)) {
    list_t *curNode = stack->next;
    while(curNode != stack) {
        if (compareFunc((void*)curNode, key)==0) 
            return 1;
        curNode = curNode->next;
    }
    return 0;
}